//
//  HeadButton.m
//  项目三
//
//  Created by rimi1 on 2016/12/10.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "HeadButton.h"

@implementation HeadButton

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.left];
        [self addSubview:self.centerLine];
        [self addSubview:self.right];
        [self addSubview:self.line];
    }
    return self;
}

#pragma mark - respondsTo...

- (void)respondsToButton:(UIButton *)sender {
    if (self.tapButton) {
        self.tapButton(sender);
    }
}

#pragma mark - get

- (UIButton *)left {
    
    if (!_left) {
        
        _left = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width/2 - 0.5, self.bounds.size.height - 2)];
        [_left setTitle:@"关注" forState:UIControlStateNormal];
        [_left setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_left setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        [_left addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        _left.tag = 100;
        
    }
    return _left;
}

- (UIView *)centerLine {
    
    if (!_centerLine) {
        
        CGFloat y = 5;
        _centerLine = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.left.frame), y, 1, self.bounds.size.height - y * 2)];
        _centerLine.backgroundColor = [UIColor lightGrayColor];
        
    }
    return _centerLine;
}

- (UIButton *)right {
    
    if (!_right) {
        
        _right = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.centerLine.frame), CGRectGetMinY(self.left.frame), CGRectGetWidth(self.left.bounds), CGRectGetHeight(self.left.bounds))];
        [_right setTitle:@"粉丝" forState:UIControlStateNormal];
        [_right setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        [_right setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_right addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        _right.tag = 101;
        
    }
    return _right;
}

- (UIView *)line {
    
    if (!_line) {
        
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.left.frame), CGRectGetWidth(self.left.bounds), 2)];
        _line.backgroundColor = [UIColor blackColor];
        
    }
    return _line;
}

@end
















